package com.atom.module.lib.opengles

import com.atom.module.lib.opengles.geometry.Frustum
import com.atom.module.lib.opengles.geometry.Matrix4
import com.atom.module.lib.opengles.geometry.Vec3
import com.atom.module.lib.opengles.geometry.Viewport
import org.junit.Test

class Matrix4Test {

    @Test
    fun `Matrix4 fun crate`() {
        val matrix = Matrix4()
        matrix.setTranslation(0.0, 0.0, 1.0);
        var p = Vec3(1.0, 0.0, 1.0)
        var p2 = Vec3(1.0, 0.0, 0.0)
        var p3 = Vec3(0.0, 0.0, 1.0)
        p.multiplyByMatrix(matrix)
        p2.multiplyByMatrix(matrix)
        p3.multiplyByMatrix(matrix)
        println(" 1 matrix -> ${matrix}")
        println(" 1 p  -> ${p}")
        println(" 1 p2 -> ${p2}")
        println(" 1 p3 -> ${p3}")
        matrix.transpose()
        p = Vec3(1.0, 0.0, 1.0)
        p2 = Vec3(1.0, 0.0, 0.0)
        p3 = Vec3(0.0, 0.0, 1.0)
        p.multiplyByMatrix(matrix)
        p2.multiplyByMatrix(matrix)
        p3.multiplyByMatrix(matrix)
        println(" 2 matrix -> ${matrix}")
        println(" 2 p  -> ${p}")
        println(" 2 p2 -> ${p2}")
        println(" 2 p3 -> ${p3}")
    }

    @Test
    fun `test constructor`() {
        var matrix = Matrix4()
        println(matrix)
        matrix = Matrix4(
            1.0, 1.0, 1.0, 1.0,
            1.0, 1.0, 1.0, 1.0,
            1.0, 1.0, 1.0, 1.0,
            1.0, 1.0, 1.0, 1.0
        )
        println(matrix)
    }

    @Test
    fun `test transpose()`() {
        var matrix = Matrix4()
        matrix.setScale(2.0, 2.0, 2.0)
        println(matrix)
        matrix.multiplyByTranslation(1.0, 2.0, 3.0)
        println(matrix)
        matrix.transpose()
        println(matrix)
    }

    @Test
    fun `test setToPerspectiveProjection()`() {
        var matrix = Matrix4()
        matrix.setToPerspectiveProjection(1.0, 1.0, 90.0, 1.0, 2.0)
        println(matrix)
        val f = Frustum()
        f.setToModelviewProjection(matrix  , Matrix4().setTranslation(0.0, 0.0 , 1.0) , Viewport(0,0,2,2 ))
        println(f)
    }
}